﻿using Product.API.ISerivces.Material;
using Repository.communal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Product.API.Serivces.Material
{
    /// <summary>
    /// 物料服务实现类
    /// </summary>
    public class MaterialSerivces : IMaterialSerivces
    {
        /// <summary>
        /// 物料仓储
        /// </summary>
        private readonly IBaseRepository<ERP.Domain.Products.Material> materialRepository;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="materialRepository">物料仓储</param>
        public MaterialSerivces(IBaseRepository<ERP.Domain.Products.Material> materialRepository)
        {
            this.materialRepository = materialRepository;
        }

        /// <summary>
        /// 物料添加
        /// </summary>
        /// <param name="material">物料信息</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> CreateMaterial(ERP.Domain.Products.Material material)
        {
            var result = materialRepository.AddAsync(material);
            return result;
        }

        /// <summary>
        /// 删除物料（逻辑）
        /// </summary>
        /// <param name="Id">物料主键</param>
        /// <returns>返回受影响行数</returns>
        public async Task<int> DeleteMaterial(int Id)
        {
            var data = await materialRepository.GetModelAsync(Id);
            data.IsDelete = true;
            int result = await materialRepository.Update(data);
            return result;
        }

        /// <summary>
        /// 物料修改
        /// </summary>
        /// <param name="material">物料信息</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> UpdateMaterial(ERP.Domain.Products.Material material)
        {
            var rseult = materialRepository.Update(material);
            return rseult;
        }

    }
}
